<template>
	<page-meta :page-style="`overflow:${pagesMetaStatus ? 'hidden' : 'visible'};height:${pagesMetaStatus ? '100%' : 'auto'};`"></page-meta>
	<view class="pagesIndex">
		<!-- page-meta 只能是页面内的第一个节点 -->
		
		<view class="pagesPadding">
			<pagesTop></pagesTop>
			<pagesServiceCard v-if="logInType!=1"></pagesServiceCard>
		</view>
		<view class="introduceContent" :class="showKfSticky?'sticky':''" v-if="logInType!=1">
			<view @click="clickIntroduce(item.num)" v-for="(item, index) in introduceArr" :key="index">
				<view class="introduceBox">
					<view class="introduceBox_image">
						<u--image :src="item.icon" width="100rpx" height="100rpx"></u--image>
					</view>

					<view :class="introduceNumCur==item.num?'name':''" class="introduceBox_text">
						{{item.name}}
					</view>
				</view>

			</view>
		</view>

		<view class="pagesIndexContainers" :class="logInType==1?'active':''">
			<!-- 专家介绍 -->
			<pagesExpert ref="pagesExpert" v-if="pageCur==='pagesExpert'" :entranceType='1'></pagesExpert>
			<pagesPlatform ref="pagesPlatform" v-if="pageCur==='pagesPlatform'"></pagesPlatform>
			<!-- <pagesGuide ref="pagesGuide" currentCode="pagesGuide"  v-if="pageCur==='pagesGuide'"></pagesGuide> -->
			<pagesEntrance ref="pagesEntrance" v-if="pageCur==='pagesEntrance'"></pagesEntrance>
			<pagesMy ref="pagesMy" v-if="pageCur==='pagesMy'"></pagesMy>
			<pagesKf ref="pagesKf" v-if="pageCur==='pagesKf'"></pagesKf>
			<!-- <view class="kfIconBox" v-if="showKf">
				<pagesKf @closeKf='closeKf' @handleKfSticky="handleKfSticky"></pagesKf>
			</view> -->

		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import config from '@/config'
	import {
		mapState
	} from 'vuex'
	import {
		getToken
	} from '@/utils/auth'
	import {
		login
	} from '../../api/login'
	import pagesExpert from '@/components/pagesExpert/pagesExpert.vue'
	import pagesPlatform from '@/components/pagesPlatform/pagesPlatform.vue'
	// import pagesGuide from '@/components/pagesGuide/pagesGuide.vue'
	import pagesEntrance from '@/components/pagesEntrance/pagesEntrance.vue'
	import pagesMy from '@/components/pagesMy/pagesMy.vue'
	import pagesKf from '@/components/pagesKf/pagesKf.vue'


	export default {
		components: {
			pagesExpert,
			pagesPlatform,
			// pagesGuide,
			pagesEntrance,
			pagesMy,
			pagesKf,

		},
		computed: {
			...mapState({
				logInType: state => state.user.logInType, //1医生  2个人  普通
			}),
		},
		data() {
			return {
				globalConfig: config,
				pagesMetaStatus:false,
				showKf:true,
				showKfSticky:true,
				pageCur: 'pagesExpert',
				introduceNumCur: 0,
				introduceArr: [],
				introduceArr0: [{
					icon: '/static/images/index/entrance1.png',
					num: 0,
					name: '专家介绍',
					show: true,
				}, {
					icon: '/static/images/index/entrance2.png',
					num: 1,
					name: '平台介绍',
					show: true,
				}, {
					icon: '/static/images/index/entrance3.png',
					num: 2,
					name: '会诊指南',
					show: true,
				}, {
					icon: '/static/images/index/entrance4.png',
					num: 3,
					name: '联系客服',
					show: true,
				}, {
					icon: '/static/images/index/entrance5.png',
					num: 4,
					name: '登录入口',
					show: true,
				}],
				introduceArr1: [
					// 	{
					// 	icon: '/static/images/index/entrance1.png',
					// 	num: 0,
					// 	name: '专家介绍',
					// 	show: true,
					// }, 
					{
						icon: '/static/images/index/entrance2.png',
						num: 1,
						name: '平台介绍',
						show: true,
					}, {
						icon: '/static/images/index/entrance3.png',
						num: 2,
						name: '会诊指南',
						show: true,
					}, {
						icon: '/static/images/index/entrance4.png',
						num: 5,
						name: '医生工作站',
						show: true,
					}
				],
				introduceArr2: [{
					icon: '/static/images/index/entrance1.png',
					num: 0,
					name: '专家介绍',
					show: true,
				}, {
					icon: '/static/images/index/entrance2.png',
					num: 1,
					name: '平台介绍',
					show: true,
				}, {
					icon: '/static/images/index/entrance3.png',
					num: 2,
					name: '会诊指南',
					show: true,
				}, {
					icon: '/static/images/index/entrance4.png',
					num: 3,
					name: '联系客服',
					show: true,
				},{
					icon: '/static/images/index/entrance5.png',
					num: 4,
					name: '我的订单',
					show: true,
				}],

			}
		},
		onLoad(options) {
			if(this.globalConfig.isToB){
				if (getToken()) {
					
				} else {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
			}
			// 接收传递参数
			console.log(options)
			if (options) {
				let hospitalCode = {}
				if (options.hd) { //医院id 住院医院id
					// uni.setStorageSync('hd', options.hd)
					hospitalCode.hd = +options.hd
				}
				if (options.pd) { // 科室id 
					// uni.setStorageSync('pd', options.pd)
					hospitalCode.pd = +options.pd
				}
				if (options.area) { //病区
					// uni.setStorageSync('area', options.area)
					hospitalCode.area = options.area
				}
				if (hospitalCode.hd || hospitalCode.pd || hospitalCode.area) {
					this.$store.commit('setHospitalCode', hospitalCode)
					console.log('hospitalCode--',hospitalCode)
				}
				
				let delivery = ''
				if (options.delivery) { //现场送检
					delivery = +options.delivery
					this.$store.commit('setDelivery', delivery)
				}
				
				
				
			}
			if (this.logInType == 1) { //医生
				this.introduceArr = [] //this.introduceArr1
				this.pageCur = 'pagesEntrance'
				this.introduceNumCur = 5
			} else if (this.logInType == 2) { //病人
				this.introduceArr = this.introduceArr2
				if (options.pageCur) {
					this.pageCur = options.pageCur
					this.introduceNumCur = +options.introduceNumCur
				} else {
					this.pageCur = 'pagesExpert'
					this.introduceNumCur = 0
				}


			} else {
				this.introduceArr = this.introduceArr0
				this.pageCur = 'pagesExpert'
				this.introduceNumCur = 0
			}
		},
		onShow() {
			if (this.pageCur == 'pagesMy') {
				setTimeout(() => {
					this.$refs.pagesMy.init()
				}, 600)
			} else if (this.pageCur == 'pagesEntrance') {
				setTimeout(() => {
					this.$refs.pagesEntrance.init()
					console.log('返回到医生展示页')
				}, 600)
				
			}

		},
		onPageScroll(e) { //onScroll
			if (this.pageCur === 'pagesExpert') { //专家列表
				this.$refs.pagesExpert.onScroll(e)
			} 
			// else if (this.pageCur === 'pagesGuide') { //会诊指南
			// 	this.$refs.pagesGuide.onScroll(e)
			// }
		},
		// 上拉加载
		onReachBottom(e) {
			if (this.pageCur === 'pagesExpert') { //专家列表
				this.$refs.pagesExpert.getReachBottom()
			} 
			// else if (this.pageCur === 'pagesGuide') { //会诊指南
			// 	this.$refs.pagesGuide.getReachBottom()
			// } 
			else if (this.pageCur === 'pagesMy') { // 我的订单
				this.$refs.pagesMy.getReachBottom()
			} else if (this.pageCur === 'pagesEntrance') { // 医生工作入口
				this.$refs.pagesEntrance.getReachBottom()
			}

		},
		// onShow() {
		// 	if (this.logInType == 1) { //医生
		// 		this.introduceArr = []//this.introduceArr1
		// 		this.pageCur = 'pagesEntrance'
		// 		this.introduceNumCur = 5
		// 	} else if (this.logInType == 2) { //病人
		// 		this.introduceArr = this.introduceArr2
		// 		this.pageCur = 'pagesExpert'
		// 		this.introduceNumCur = 0
		// 	} else {
		// 		this.introduceArr = this.introduceArr0
		// 		this.pageCur = 'pagesExpert'
		// 		this.introduceNumCur = 0
		// 	}
		// },
		methods: {
			closeKf(){
				this.showKf=false
			},
			handleKfSticky(data){
				this.showKfSticky=data
				console.log("999-this.kfShowSticky",data)
				
			},
            showDailog(){
				this.pagesMetaStatus=true
			},
			closeDailog(){
				this.pagesMetaStatus=false
			},
			clickIntroduce(num) {
				this.introduceNumCur = num
				if (num === 0) {
					this.pageCur = 'pagesExpert'
				} else if (num === 1) {
					this.pageCur = 'pagesPlatform'
				} else if (num === 2) {
					uni.navigateTo({
						url:`/subPackages/consultationGuide/consultationGuide?current=1`
					})
					//this.pageCur = 'pagesGuide'
				} else if (num === 3) {
					// uni.reLaunch({
					// 	url: '/pages/login/login'
					// })
					this.pageCur = 'pagesKf'

				} else if (num === 4) {
					if (getToken()) {
						this.pageCur = 'pagesMy'
					} else {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}

				} else if (num === 5) {
					if (getToken()) {
						this.pageCur = 'pagesEntrance'
					} else {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}
				}
			},
			NavChange: function(e) {
				console.log(e)
				this.PageCur = e.currentTarget.dataset.cur
			}
		}
	}
</script>

<style lang="scss" scoped>
	.sticky {
		position: sticky;
		// background: #000;
		z-index: 9;
		top: 0rpx;
	}
	.pagesIndex {
		.introduceContent {
			padding: 16rpx 20rpx;
			background: #fff;
			display: flex;
			justify-content: space-between;
			box-shadow: 0 6rpx 8rpx 0px rgba(32, 108, 228, 0.3);

			.introduceBox {
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				width: 120rpx;
				font-size: 24rpx;

				&_image {
					display: flex;
					justify-content: center;
					align-items: center;
					// width:100rpx;
					// height:100rpx;
					// background-color: #E5F6FF;
					border-radius: 100rpx;
				}

				&_text {
					font-size: 26rpx;
					line-height: 40rpx;
					color: #333333;
				}

				&_text.name {
					color: #3898FF;

				}
			}
		}

		.pagesIndexContainers.active {
			padding-top: 0rpx;
		}

		.pagesIndexContainers {
			padding-top: 24rpx;
			
			position: relative;
			.kfIconBox{
				
				position: fixed;
				right: 40rpx;
				bottom: 200rpx;
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				font-size: 16rpx;
				box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.3);
				background: #fff;
				font-size: 20rpx;
				color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
				
				
			}
		}
		
	}
</style>